package dal;

import java.io.IOException;
import java.io.Serializable;


/**
 * The persistent class for the pets database table.
 * 
 */
public class Pet implements IPet,Serializable {
	private static final long serialVersionUID = 1L;
	
	private int id;
	private String long_desc;
	private Pet_type pet_type;
	private User deliver_User; 
	private byte[] picture;
	private String short_desc;	
	private String name;
	
  
    public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Pet() {
    }

    
    public Pet(Pet_type type,String name,String shortDesc,String longDesc){
    	this.name = name;
    	this.pet_type = type;
    	this.short_desc = shortDesc;
    	this.long_desc = longDesc;
    }
    
    public Pet(Pet_type type,String shortDesc,String longDesc){
    	this.pet_type = type;
    	this.short_desc = shortDesc;
    	this.long_desc = longDesc;
    }
    
    
    public void setPetType(Pet_type type){
    	this.pet_type = type;
    }
    
    public void setDeliverUser(User deliverUser){
    	this.deliver_User = deliverUser;
    }
	
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


    
	public String getLong_desc() {
		return this.long_desc;
	}

	public void setLong_desc(String long_desc) {
		this.long_desc = long_desc;
	}



	public Pet_type getPet_type() {
		return pet_type;
	}
 


	public User getDeliver_user() {
		return deliver_User;
	}



	public byte[] getPicture() {
		return this.picture;
	}

	public void setPicture(byte[] picture) {
		this.picture = picture;
	}


	public String getShort_desc() {
		return this.short_desc;
	}

	public void setShort_desc(String short_desc) {
		this.short_desc = short_desc;
	}
	
	public boolean isDeliveredByUser(final User userToCheck){
		return ((null != userToCheck) && (this.getDeliver_user().equals(userToCheck)));
	}
	
	private void writeObject(java.io.ObjectOutputStream out) throws IOException{
		out.writeInt(id);
		out.writeUTF(long_desc);
		out.writeUTF(name);
		out.writeUTF(short_desc);
		out.writeObject(pet_type);
		out.writeObject(deliver_User);
		out.writeInt(0);
	}
	
	private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException{
		
		id = in.readInt();
		long_desc = in.readUTF();
		name = in.readUTF();
		short_desc = in.readUTF();
		pet_type = (Pet_type)in.readObject();
		deliver_User = (User)in.readObject();
		int length = in.readInt();
		
		if (0 != length){
			picture = new byte[length];
			in.readFully(picture);	
		}else{
			picture = null;
		}
			
		
	}

}